package com.xbts.web.controller.cloud;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnContractTemplate;
import com.xbts.system.service.ICnContractTemplateService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 合同模板Controller
 * @author xbts
 * @date 2023-10-16
 */
@Api("合同模板")
@RestController
@RequestMapping("/system/template")
public class CnContractTemplateController extends BaseController {

    @Autowired
    private ICnContractTemplateService cnContractTemplateService;

    /**
     * 查询合同模板列表
     */
    @ApiOperation("查询合同模板列表")
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnContractTemplate cnContractTemplate) {
        startPage(cnContractTemplate);
        List<CnContractTemplate> list = cnContractTemplateService.selectCnContractTemplateList(cnContractTemplate);
        return getDataTable(list);
    }

    /**
     * 导出合同模板列表
     */
    @ApiOperation("导出合同模板列表")
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "合同模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnContractTemplate cnContractTemplate) {
        List<CnContractTemplate> list = cnContractTemplateService.selectCnContractTemplateList(cnContractTemplate);
        ExcelUtil<CnContractTemplate> util = new ExcelUtil<CnContractTemplate>(CnContractTemplate.class);
        util.exportExcel(response, list, "合同模板数据");
    }

    /**
     * 获取合同模板详细信息
     */
    @ApiOperation("获取合同模板详细信息")
    @ApiImplicitParam(name = "id", value = "合同模板ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cnContractTemplateService.selectCnContractTemplateById(id));
    }

    /**
     * 新增合同模板
     */
    @ApiOperation("新增合同模板")
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "合同模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnContractTemplate cnContractTemplate) {
        return toAjax(cnContractTemplateService.insertCnContractTemplate(cnContractTemplate));
    }

    /**
     * 修改合同模板
     */
    @ApiOperation("修改合同模板")
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "合同模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnContractTemplate cnContractTemplate) {
        return toAjax(cnContractTemplateService.updateCnContractTemplate(cnContractTemplate));
    }

    /**
     * 删除合同模板
     */
    @ApiOperation("删除合同模板")
    @ApiImplicitParam(name = "ids", value = "合同模板ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "合同模板", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(cnContractTemplateService.deleteCnContractTemplateByIds(ids));
    }
}
